package com.meatball.doc

import kastree.ast.Node
import kastree.ast.Visitor
import kastree.ast.Writer
import kastree.ast.psi.Converter
import kastree.ast.psi.Parser
import java.io.File

object CommentExtractor {
    @JvmStatic
    fun main(args: Array<String>) {
        println("1111111111111111111111111")
        val files = collectFiles(File("src/main"))
        println("Found ${files.size} source files:")
        files.forEach {
            println(it.path)
            kotlinFile(it)
        }
    }

    private fun collectFiles(dir: File): List<File> {
        val result = mutableListOf<File>()
        dir.listFiles()?.forEach { file ->
            println(file.name)
            when {
                file.isDirectory -> result.addAll(collectFiles(file))
                file.extension == "kt" || file.extension == "java" -> result.add(file)
            }
        }
        return result
    }

    private fun kotlinFile(file: File) {
        println(file.readText())
        file.forEachLine { line ->
            println(line)
        }
    }

/*    private fun kotlinFile(file: File) {
        val extrasMap = Converter.WithExtras()
        val ff = Parser(extrasMap).parseFile(file.readText().trimIndent())
        var strings = emptyList<String>()
        Visitor.visit(ff) {v, _ ->
            println(v)
        }
    }*/
}